import{ut as e}from"./B603vO-13smUKN.js";import{J as t,O as n,fn as r,vn as i,xn as a}from"./CIxmKYxc4tZcJF.js";import{o}from"./DCh5OO9H1Mqcs9.js";var s=e(`oui-stack-registry`),c=/^oui-stack-\d+$/,l=new WeakMap;function u(e){return typeof e==`function`&&!(`render`in e)&&!(`setup`in e)&&!(`props`in e)}function d(e){if(!u(e))return e;let t=l.get(e);return t||(t=n(e),l.set(e,t)),t}function f(e){let t=e.indexOf(`:`);return t>=0?{key:e.slice(0,t),arg:e.slice(t+1)}:{key:e,arg:``}}function p(e,t=`,`,n=0){let r=[];for(let t of e.entries.value.slice(n)){let e=t.meta?.routeToken??t.id;if(typeof e!=`string`||c.test(e))break;r.push(e)}return r.join(t)}function m(e,t,n,r=`,`,i=0){i>0?e.popTo(i-1,{force:!0}):e.clear();for(let i of t.split(r).filter(Boolean)){let{key:t,arg:r}=f(i),a=n[t];if(!a){s.warn(`no registry entry for token key "${t}" - column dropped on rebuild`);continue}e.push(d(a.component),a.resolve?.(r),{id:i,title:a.titleOf?.(r)??a.title,header:a.header,width:a.width,minWidth:a.minWidth,maxWidth:a.maxWidth,resizeable:a.resizeable,grow:a.grow,widthKey:a.widthKey,padding:a.padding,pinnable:a.pinnable,meta:{routeToken:i,...a.urlMode?{urlMode:a.urlMode}:{}}})}}var h=e(`use-oui-stack`),g=0;function _(e){return{...e,component:r(e.component)}}function v(e=[],t={}){let n=t.registry,o=a(Object.freeze(e.map(_))),s=i(Math.max(0,o.value.length-1)),c=i(`init`);function l(e){o.value=Object.freeze(e),s.value=Math.min(Math.max(s.value,0),Math.max(e.length-1,0))}function u(e){return o.value.findIndex(t=>t.id===e)}function p(e,t,n={}){return{id:n.id??`oui-stack-${++g}`,component:r(e),props:t,title:n.title,header:n.header,width:n.width,minWidth:n.minWidth,maxWidth:n.maxWidth,resizeable:n.resizeable,grow:n.grow,trailing:n.trailing,widthKey:n.widthKey,background:n.background,padding:n.padding,pinnable:n.pinnable,pinned:n.pinned,meta:n.meta}}function m(){let e=-1;return o.value.forEach((t,n)=>{t.pinned&&(e=n)}),e}function v(e,t,n={}){if((n.dedupe??!0)&&n.id!=null){let e=u(n.id);if(e>=0){let t=o.value[e];return l(o.value.slice(0,e+1)),s.value=e,c.value=`pop`,t}}let r=p(e,t,n);return l([...o.value,r]),s.value=o.value.length-1,c.value=`push`,r}function y(e,t,r){let{key:i,arg:a}=f(e),o=n?.[i];if(!o)throw h.warn(`push(${JSON.stringify(e)}): no registry entry - bind one via useOuiStack(initial, { registry })`),Error(`useOuiStack.push: no registry entry for key "${i}"`);let s=e.includes(`:`),c=t??(s?o.resolve?.(a):void 0),l=s?a:t==null?void 0:o.toArg?.(t),u=r.id??(l==null?i:`${i}:${l}`),p=r.title??(l==null?void 0:o.titleOf?.(l))??o.title;return{component:d(o.component),props:c,opts:{...r,id:u,title:p,header:r.header??o.header,width:r.width??o.width,minWidth:r.minWidth??o.minWidth,maxWidth:r.maxWidth??o.maxWidth,resizeable:r.resizeable??o.resizeable,grow:r.grow??o.grow,widthKey:r.widthKey??o.widthKey,padding:r.padding??o.padding,pinnable:r.pinnable??o.pinnable,pinned:r.pinned,meta:{routeToken:u,...o.urlMode?{urlMode:o.urlMode}:{},...r.meta}}}}function b(e,t,n={}){if(typeof e!=`string`)return v(e,t,n);let r=y(e,t,n);return v(r.component,r.props,r.opts)}function x(){if(o.value.length<=1)return;let e=o.value[o.value.length-1];return l(o.value.slice(0,-1)),s.value=o.value.length-1,c.value=`pop`,e}function S(e,t={}){let n=Math.max(0,Math.min(e,o.value.length-1));t.force||(n=Math.max(n,m())),!(n>=o.value.length-1)&&(l(o.value.slice(0,n+1)),s.value=n,c.value=`pop`)}function C(e,t,n={}){let r=Math.max(0,Math.min(n.index??o.value.length-1,o.value.length)),i=p(e,t,n);return l([...o.value.slice(0,r),i]),s.value=o.value.length-1,c.value=`replace`,i}function w(e,t,n={}){if(typeof e!=`string`)return C(e,t,n);let r=y(e,t,n);return C(r.component,r.props,{...r.opts,index:n.index})}function T(){l([]),s.value=0,c.value=`pop`}function E(e,t){let n=u(e);if(n<0)return;let r=o.value.slice();r[n]={...r[n],...t,id:e,component:r[n].component},o.value=Object.freeze(r)}return{entries:o,activeIndex:s,lastOp:c,registry:n,push:b,pop:x,popTo:S,replace:w,clear:T,indexOfId:u,update:E}}function y(){let e=t(o,null);if(!e)throw Error(`injectOuiStack() must be called within an <OuiStack>`);return e}export{d as a,f as i,v as n,p as o,m as r,y as t};